const { check } = require("../../lib/check")
const { searchToken, editToken, clearToken } = require("../../model/token")

function reFreshToken(ctx) {
  let token = ctx.cookies.get("token")
  const time = (new Date()).getTime()
  clearToken()
  const findToken = searchToken(token)
  check(!!findToken, 'User_Login_Outdate')
  editToken({ token: findToken.token, time: time + 600000 })
}

module.exports = {
  reFreshToken
}